<template>
    <div class="login">
        <div class="login-left">
            <div class="loginLeft">
                <div class="login-left-icon">
                    <div class="login_logo" @click="$navTo('/home/index')">
                        <img src="./../../assets/logo.png" alt="">
                    </div>
                </div>
                <div class="login-left-cont">
                    <div class="login-left-body">
                        <div class="hej">Hej!</div>
                        <div class="txt">为大众创造更美好的日常生活</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="login-right">
            <div class="login-right-content" v-if="logOrReg==1">
                <div class="LoginRightInner">
<!--                    <div>-->
<!--                        <div class="phoneLog">-->
<!--                            <h2 class="title">欢迎来到天威</h2>-->
<!--                        </div>-->
<!--                        <el-form ref="form" :model="form3">-->
<!--                            <el-form-item label="">-->
<!--                                <el-input v-model="form3.name" placeholder="手机号"></el-input>-->
<!--                            </el-form-item>-->
<!--                            <el-form-item label="" class="code">-->
<!--                                <el-input v-model="form3.captcha" placeholder="验证码"></el-input>-->
<!--                                <button class="code-btn">获取验证码</button>-->
<!--                            </el-form-item>-->
<!--                            <el-form-item label="" class="check">-->
<!--                                <el-checkbox class="check">-->
<!--                                    我已阅读天威<a href="javascript:;" class="link">隐私政策</a>-->
<!--                                </el-checkbox>-->
<!--                            </el-form-item>-->
<!--                            <el-form-item label="">-->
<!--                                <el-button type="primary" class="btn">登陆/注册</el-button>-->
<!--                            </el-form-item>-->
<!--                        </el-form>-->
<!--                    </div>-->
                    <div>
                        <div class="right-head">
                            <div class="head-cont">
                                <h2>账号密码登陆</h2>
                                <p>您可以使用注册的账号与设置过的密码进行登录</p>
                            </div>
                            <div class="head-icon"><img
                                src="https://static.web.ikea.cn/static/images/pc/memberClub/account_pwd_login.svg"
                                alt=""></div>
                        </div>
                        <el-form ref="form" :model="form2">
                            <el-form-item label="">
                                <el-input v-model="form2.username" placeholder="手机号/邮箱"></el-input>
                            </el-form-item>
                            <el-form-item label="">
                                <el-input v-model="form2.password" placeholder="密码"></el-input>
                            </el-form-item>
                            <el-form-item label="" class="check">
                                <a href="javascript:;" class="link_foget">忘记密码？</a>
                            </el-form-item>
                            <el-form-item label="">
                                <el-button type="primary" class="btn" @click="login">登陆</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                    <div class="other-login">
                        <div class="tit"><a href="javascript:;" class="register" @click="logOrReg =2">立即注册</a></div>
<!--                        <div class="flex">-->
<!--                            <div class="other-methods_item" v-if="type !=2" @click="type =2">-->
<!--                                <div class="icon-box">-->
<!--                                    <img src="https://static.web.ikea.cn/static/images/user/icon_Wechat_Highlight.svg"-->
<!--                                         alt="">-->
<!--                                </div>-->
<!--                                <div class="txt-box">微信登陆</div>-->
<!--                            </div>-->
<!--                            <div class="other-methods_item" v-if="type !=3" @click="type =3">-->
<!--                                <div class="icon-box">-->
<!--                                    <img src="https://static.web.ikea.cn/static/images/user/icon_user.svg" alt="">-->
<!--                                </div>-->
<!--                                <div class="txt-box">账号密码登陆</div>-->
<!--                            </div>-->
<!--                            <div class="other-methods_item" v-if="type !=1" @click="type =1">-->
<!--                                <div class="icon-box">-->
<!--                                    <img src="https://static.web.ikea.cn/static/images/user/icon_phone.svg" alt="">-->
<!--                                </div>-->
<!--                                <div class="txt-box">短信验证码登陆</div>-->
<!--                            </div>-->
<!--                        </div>-->
                    </div>
                </div>
            </div>
            <div class="login-right-content" v-else>
                <div class="LoginRightInner">
                    <div>
                        <div class="phoneLog">
                            <h2 class="title">欢迎来到天威</h2>
                        </div>
                        <el-form ref="form" :model="form">
                            <el-form-item label="">
                                <el-input v-model="form.username" placeholder="账号手机号"></el-input>
                            </el-form-item>
                            <el-form-item label="">
                                <el-input type="password" v-model="form.password" placeholder="密码"></el-input>
                            </el-form-item>
                            <el-form-item label="">
                                <el-input type="password" v-model="form.password2" placeholder="确认密码"></el-input>
                            </el-form-item>
                            <el-form-item label="" class="check">
                                <el-checkbox class="check" v-model="checked">
                                    我已阅读天威<a href="javascript:;" class="link">隐私政策</a>
                                </el-checkbox>
                                <a href="javascript:;" class="login_url" @click="logOrReg =1">账号登陆</a>
                            </el-form-item>
                            <el-form-item label="">
                                <el-button type="primary" class="btn" @click="register">立即注册</el-button>
                            </el-form-item>
                        </el-form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script>
import request from "../../utils/request";

export default {
    data() {
        return {
            form: {},
            form2: {},
            type: 3, //1短信验证码登陆 2.微信。3账号和密码
            logOrReg: 1, //1登陆 2//注册
            checked: false
        }
    },
    created() {
        var token = localStorage.getItem('token')
        if (token) {
            this.$message('您已登录，无需重复登录')
            this.$router.go(-1);
        }
    },
    methods: {
        register() {
            if (!this.checked) {
                this.$message({
                    message: '请先仔细阅读《天威隐私政策》，确认是否同意',
                    type: 'warning'
                });
                return false
            }
            request.post('index/reg', this.form).then(res => {
                if (res.code == 200) {
                    localStorage.setItem('token', res.data.token)
                    localStorage.setItem('nickname', res.data.nickname)
                    this.$router.go(-1);
                } else {
                    this.$message({message: res.msg, type: 'warning'})
                }
            })
        },
        login() {
            request.post('/index/login', this.form2).then(res => {
                if (res.code == 200) {
                    localStorage.setItem('token', res.data.token)
                    localStorage.setItem('nickname', res.data.nickname)
                    this.$router.go(-1);
                } else {
                    this.$message({message: res.msg, type: 'warning'})
                }
            })
        }
    }
}
</script>
<style lang="scss">
.login {
    max-width: none;
    min-height: 100vh;
    padding-top: 0;
    width: 100%;
    height: auto;
    padding-left: 0;
    padding-right: 0;
    display: flex;
    box-sizing: content-box;

    .login_url {
        float: right;
        color: #409eff;
        font-size: 14px;
    }

    .link {
        color: #409eff;
    }

    .check {
        font-size: 12px;

        .el-checkbox__label {
            font-size: 12px !important;
            color: #999 !important;
            font-weight: 400 !important;

        }
    }

    .login-left {
        width: 40%;

        .loginLeft {
            position: relative;
            width: 100%;
            background: #0058a3;
            height: 100%;
            display: flex;
            flex-direction: column;

            .login-left-icon {
                padding: 24px;
                display: flex;
                align-items: center;

                .login_logo {
                    cursor: pointer;
                }
            }

            .login-left-cont {
                display: flex;
                justify-content: center;
                align-items: center;
                flex: 1;
                margin: -200px 23.6% 0;

                .hej {
                    font-size: 50px;
                    line-height: 60px;
                    color: #ffdb00;
                    font-weight: 700;
                    margin-bottom: 32px;
                }

                .txt {
                    font-weight: 700;
                    font-size: 36px;
                    line-height: 54px;
                    color: #fff;
                }
            }
        }
    }

    .login-right {
        width: 62%;
        height: 100%;
        overflow: hidden;

        .login-right-content {
            height: 100%;
            width: 100%;
            padding: 15% 10% 10% 17%;

            .LoginRightInner {
                max-width: 500px;

                .title {
                    font-size: 30px;
                    line-height: 45px;
                    color: #111;
                    margin-bottom: 30px;
                    color: #0058a3;
                    text-align: center;
                }

                .el-form-item {
                    margin-bottom: 40px;

                    .el-input__inner {
                        border: none;
                        border-bottom: 1px solid #DCDFE6;
                        border-radius: 0;
                    }

                    .el-input__inner {
                        padding-left: 0;
                    }
                }

                .code {
                    .el-form-item__content {
                        display: flex;
                    }

                    .el-input {
                        flex: 1;
                    }

                    .code-btn {
                        width: 140px;
                        right: 0;
                        height: 40px;
                        line-height: 40px;
                        border: 1px solid #DCDFE6;
                        margin-left: 4px;
                        border-radius: 20px;
                        cursor: pointer;
                        font-size: 12px;
                        color: #999;
                    }
                }

                .btn {
                    width: 100%;
                    border-radius: 40px;
                }

                .other-login {
                    .tit {
                        font-size: 16px;
                        line-height: 24px;
                        color: #484848;
                        margin-bottom: 20px;

                        .register {
                            float: right;
                            color: #409eff;
                            font-size: 14px;
                        }
                    }

                    .flex {
                        .other-methods_item {
                            display: inline-block;
                            margin-right: 30px;
                            text-align: center;
                            cursor: pointer;
                        }

                        .icon-box {
                            width: 50px;
                            height: 50px;
                            border: 1px solid #959595;
                            border-radius: 50px;
                            text-align: center;
                            margin: 0 auto;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                        }

                        .txt-box {
                            font-size: 12px;
                            line-height: 20px;
                            color: #111;
                            margin-top: 12px;
                            white-space: nowrap;
                        }
                    }
                }
            }

            .link_foget {
                color: #999;
                font-size: 12px;
                text-decoration: underline;
            }

            .wrp_code {
                padding: 30px 0;
                text-align: center;
            }

            .right-head {
                margin-bottom: 30px;
                display: flex;
                justify-content: center;
                width: 100%;
                align-items: center;

                .head-cont {
                    margin-right: 30px;
                    flex: 1;

                    h2 {
                        font-size: 30px;
                        line-height: 50px;
                        margin: 0;
                        margin-bottom: 14px;
                    }

                    p {
                        font-size: 18px;
                        line-height: 28px;
                        color: #484848;
                    }
                }
            }
        }
    }
}
</style>